from selenium.webdriver.common.by import By
from autoTest_ecshop.base_page.base import BasePage
from autoTest_ecshop.utils.log_util import logger


class LoginPage(BasePage):
    login_btn_idnex = (By.XPATH,'//*[@id="ECS_MEMBERZONE"]/a[1]')
    # 用户名定位器
    login_username_loc = (By.XPATH, '/html/body/div[7]/div[1]/form/table/tbody/tr[1]/td[2]/input')
    login_password_loc = (By.XPATH, '/html/body/div[7]/div[1]/form/table/tbody/tr[2]/td[2]/input')
    login_btn = (By.XPATH, '/html/body/div[7]/div[1]/form/table/tbody/tr[4]/td[2]/input[3]')
    # 登录后提示信息
    username = (By.XPATH, '//*[@id="ECS_MEMBERZONE"]/font')
    # 用户名或密码错误提示信息
    loginRes_loc = (By.XPATH,'//div[@align="center"]/div/p[1]')

    def login_system(self, username, password):
        # 点击登录前往登陆页面
        self.btn_click(self.login_btn_idnex)
        # 输入用户名
        self.input_data(self.login_username_loc, username)
        # 输入密码
        self.input_data(self.login_password_loc, password)
        # 点击登录按钮
        self.btn_click(self.login_btn)

        logger.info("登陆成功，开始断言")
        # # 获取主页的用户文本信息用来做校验
        return self.element_text(self.loginRes_loc)
